
import csv

import facade
from xjlibrary.our_file_dir import BaseDir

curPath = BaseDir.get_file_dir_absolute(__file__)
configfile = BaseDir.get_new_path(curPath, "db.ini")
filename = r"D:\csv\article.csv"
# filename = r"F:\test2\article.csv"
listSqlVal = []
mysqlutils = facade.MysqlUtiles(configfile,
                                     "csvtosql",
                                     logger=facade.get_streamlogger())
sql = "insert ignore into `article`(rawid,app_no,pub_no,app_date,pub_date,stat,json_info,cpnum) values(%s,%s,%s,%s,%s,%s,%s,%s)"
with open(filename) as f:
    reader = csv.reader(f)
    for row in reader:
        num = reader.line_num
        if num < 1211900:
            continue
        listSqlVal.append(tuple(row))
        if num % 1000 == 1:
            print("num is :{}".format(num))
            mysqlutils.ExeSqlMany(sql,listSqlVal)
            listSqlVal.clear()
    mysqlutils.ExeSqlMany(sql, listSqlVal)
    listSqlVal.clear()